<?php
/**
 * Created by IntelliJ IDEA.
 * User: jimmyhsu
 * Date: 2017/5/16
 * Time: 18:20
 */
date_default_timezone_set("Asia/Shanghai");
$dbhost = "127.0.0.1";
$dbuser = "root";
$dbpass = "1258";
$dbname = "mobike";
$con = mysqli_connect($dbhost,$dbuser,$dbpass) or die("connect error");
mysqli_select_db($con, $dbname)or die("db error");
mysqli_query($con, "set names 'utf8'");
$sql = "select * from move";
$result = array();
if ($query = mysqli_query($con, $sql)) {
    $result['status'] = 0;
    $data = array();
    while ($row = mysqli_fetch_array($query)) {
        $start_lon = $row['start_lon'];
        $start_lat = $row['start_lat'];
        $end_lon = $row['end_lon'];
        $end_lat = $row['end_lat'];
        $bike_id = $row['ID'];
        $time = strtotime($row['time']);
        array_push($data, array('bikeId'=>$bike_id, 'start_lat'=>$start_lat, 'start_lon'=>$start_lon, 'end_lat'=>$end_lat,
            'end_lon'=>$end_lon, 'time'=>$time));
    }
    $result['data'] = $data;
} else {
    $result['status'] = 1;
    $result['error_message'] = '数据库查询失败';
}
echo json_encode($result);